package com.yanqu.road.server.cmd.activity.rank;

import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.rank.UnionActivityRank;
import com.yanqu.road.logic.cross.CrossUnionWarRankListModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.cross.CrossUnionHonorsProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.unionwar.CrossUnionWarRankMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;


@Cmd(code = CrossProtocol.C_CROSS_UNION_GROUP_ACTIVITY_GET_RANK_UNION_NAMES, desc = "获取参与活动的商会")
public class GetUnionGroupActivityRankUnionNamesCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        CrossUnionHonorsProto.UnionGroupActivityRankUnionNamesReqMsg reqMsg = CrossUnionHonorsProto.UnionGroupActivityRankUnionNamesReqMsg.parseFrom(packet.getBytes());
        List<String> unionNames = new ArrayList<>();
        //不同活动还不同榜单
        if(reqMsg.getActivityType() == eActivityType.CrossUnionWarActivity.getValue()){
            CrossUnionWarRankListModel listModel = CrossUnionWarRankMgr.getCrossUnionWarRankListModel(reqMsg.getActivityId(), 2, reqMsg.getGroupId());
            if(listModel != null){
                for (int i = 0; i < listModel.getRankList().size(); i++) {
                    UnionActivityRank uar = listModel.getRankList().get(i);
                    unionNames.add(uar.getUnionBaseInfo().getUnionName());
                }
            }
        }else {

        }

        CrossUnionHonorsProto.UnionGroupActivityRankUnionNamesRespMsg.Builder respMsg = CrossUnionHonorsProto.UnionGroupActivityRankUnionNamesRespMsg.newBuilder();
        respMsg.setActivityId(reqMsg.getActivityId());
        respMsg.setGroupId(reqMsg.getGroupId());
        respMsg.setUnionUid(reqMsg.getUnionUid());
        respMsg.setUnionNames(StringUtils.listToString(unionNames, "@#$"));
        respMsg.setRet(0);
        MessageHelper.sendPacket(serverId, 0, YanQuMessageUtils.buildMessage(Protocol.C_CROSS_UNION_GROUP_ACTIVITY_GET_RANK_UNION_NAMES_BACK, respMsg));
    }

    @Override
    public void sendData() {

    }
}
